package com.bleeth.fx.component;

import cn.hutool.core.util.StrUtil;
import com.bleeth.fx.helper.SStyleHelper;
import com.bleeth.fx.helper.ThemeHelper;
import com.bleeth.fx.helper.ThemeTypeEnum;
import com.bleeth.fx.meta.ActionFunction;
import com.bleeth.fx.meta.StyleFunction;
import javafx.scene.control.Label;
import lombok.Builder;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
@Builder
public class MLabel {

    @Builder.Default
    private String type = "DEFAULT";

    private String icon;

    @Builder.Default
    private double height = DEFAULT_HEIGHT;

    private double width;

    private String text;

    private Label label;

    private StyleFunction style;

    private ActionFunction action;

    private static final double DEFAULT_HEIGHT = 20;


    public Label make() {
        label = new Label();
        label.setPrefHeight(height);

        if (width != 0) {
            label.setPrefWidth(width);
        }

        if (StrUtil.isNotEmpty(text)) {
            label.setText(text);
        }

        if (StrUtil.isNotEmpty(icon)) {
            label.setGraphic(MIcon.builder().icon(icon).size(height / 2).build().make());
        }

        SStyleHelper.node(label)
                .addStyle("-fx-background-radius", 5)
                .addStyle("-fx-font-size", "14px");

        if (StrUtil.equalsIgnoreCase(ThemeHelper.DEFAULT, type)) {
            SStyleHelper.node(label)
                    .addHoverStyle("-fx-background-color", ThemeTypeEnum.PRIMARY_COLOR.getValue() + "22")
                    .addHoverStyle("-fx-text-fill", ThemeTypeEnum.PRIMARY_COLOR.getValue())
                    .apply();
        }else{
            SStyleHelper.node(label)
                    .addStyle("-fx-background-color", ThemeTypeEnum.getMatched(type).getValue())
                    .addStyle("-fx-text-fill", ThemeTypeEnum.WHITE_COLOR.getValue())
                    .addHoverStyle("-fx-background-color", ThemeTypeEnum.getMatched(type).getValue()+ "AA")
                    .apply();
        }

        if (style != null) {
            style.style(label);
        }

        if (action != null) {
            action.action(label);
        }
        return label;
    }


}
